<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="handleClose"
        >关闭</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <!-- 自增序号列 -->
      <el-table-column type="index" label="序号">
        <!-- 自定义索引 (可选) -->
        <template slot-scope="scope">
          {{ serial_number + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="数据集" align="center" >{{this.dataset}}</el-table-column>
      <el-table-column label="信息对象地址" align="center" prop="infoObjAddr"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="场站ID">
          <el-input v-model="this.datasetId" :disabled="true" />
        </el-form-item>
        <el-form-item label="信息对象地址" prop="infoObjAddr">
          <el-input v-model="form.infoObjAddr" type="text" placeholder="请输入字段描述前缀" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getDatasetDetail,getDatasetPointList }
  from "@/api/system/dataset";

export default {
  name: "Data",
  dicts: ['cell_type_list'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      dataList: [],
      datasetId : '',
      dataset:'',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        datasetId: ''
      },
      // 表单参数
      form: {
        id:'',
        datasetId:''
      }
    };
  },
  created() {
    const datasetId = this.$route.params.datasetId;
    this.getDatasetInfo(datasetId);
    this.loading = false;
    this.getList(datasetId);
  },
  methods: {
    /** 查询场站详情 */
    getDatasetInfo(datasetId) {
      getDatasetDetail(datasetId).then(response => {
        this.dataset = response.data.dataset;
        this.form.id = response.data.id;
      });
    },
    /** 查询数据列表 */
    getList(datasetId) {
      this.loading = true;
      this.queryParams.datasetId = datasetId;
      getDatasetPointList(this.queryParams).then(response => {
        this.dataList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        datasetId: '',
        infoObjAddr:''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    /** 返回按钮操作 */
    handleClose() {
      const obj = { path: "/system/verify/dataset" };
      this.$tab.closeOpenPage(obj);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.dictType = this.defaultDictType;
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息对象地址数据";
    }

  }

};
</script>
